<!--海外验收-->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" />
    <el-form class="flex_col flex_cell" :model="form" ref="form">
      <ex_super_table_page v-bind="option" ref="SuperTablePage" :autoLoad="false" :autoPage="false" :data="tableData"
        :span-method="objectSpanMethod" :cell-class-name="cellClassName">
        <template v-slot:table-top>
          <el-alert v-if="isAutomaticWarehouseArea == 'Y'"
            :title="$tt('label_inbound_order_will_into_auto_location', { order: inboundOrderCode })" type="warning"
            :closable="false" />
        </template>
      </ex_super_table_page>
    </el-form>


    <ex_super_dialog_form ref="dialogCheckConfirm" :title="$tt('label_acceptance_confirm')" v-bind="dialogBindCheck"
      @afterSubmitSuccess="checkSuccess">

    </ex_super_dialog_form>

    <ex_super_dialog_form ref="dialogSkuCheck" :title="$tt('label_acceptance_sku_weight_size')" v-bind="dialogSkuCheck"
      @afterSubmitSuccess="checkSkuSuccess">

    </ex_super_dialog_form>
    <ex_super_dialog_form ref="dialogAbnormal" :title="$tt('label_abnormal_info_supplement')" v-bind="dialogAbnormalCheck"
      @afterSubmitSuccess="checkAbnormalSuccess">

    </ex_super_dialog_form>
    <print_sku ref="print_sku" itemKey="skuId" />

  </div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';
import print_sku from '@/component/print/print_sku'

import router_params from '@/mixin/router_params';

export default {
  title: "title_standard_check",
  mixins: [superTablePageFunction, router_params, page_table_model_manage],

  components: {
    print_sku,
  },
  data() {
    return {
      boxFilter: [],

      form: {
        list: []
      },
      inboundOrderId: "",
      inboundOrderCode: "",
      isAutomaticWarehouseArea: 'N',


      option: {
        search: {
          default: { inboundOrderCode: '' },
          model: [
            { label: "label_inbound_code", key: "inboundOrderCode", },
          ],
        },
        actionExtra: [
          {
            if: () => !!this.inboundOrderCode,
            label: 'label_print_sku_barcode',
            click: () => {
              this.printSkuTag()
            },
          },
          { label: "label_acceptance_sku_weight_size", attrs: { type: "primary" }, click: this.checkSkuSize },
          { label: 'label_acceptance_confirm', attrs: { type: "primary" }, click: this.clickCheck },
        ],
        table: {
          url: "/wms-api/inbound/WmsInboundOverseasAcceptanceRpc/selectSkuDetail.json",
          urlDataHandle: this.dataHandle,
          specialStyle: false,
          showIndex: false,
          model: this.init_table_model(),
        }
      },

      tableData: [],
      skuUrlList: [],

      dialogBindCheck: {
        customClass: 'dialog_extra',
        submitUrl: '/wms-api/inbound/WmsInboundOverseasAcceptanceRpc/acceptance.json',
        submitDataHandle: this.submitAcceptanceDataHandle,
        form: {

          model: [
            { key: 'inboundOrderCode', label: 'label_inbound_code', formType: 'text', inputClass: "bold ", },
            { key: 'actualPieceNumber', label: 'label_confirm_acceptance_number', formType: 'text', inputClass: "bold ", },
            {
              key: 'items', label: 'label_acceptance_sku_specification',
              formType: 'table', 'max-height': 400,
              model: [
                { key: 'boxNo', label: 'label_box_code', 'min-width': 120, 'show-overflow-tooltip': true, },
                { key: 'skuOnlyCode', label: 'label_sku_only_code', 'min-width': 120, 'show-overflow-tooltip': true, },
                { key: 'skuName', label: 'label_sku_name', 'min-width': 120, 'show-overflow-tooltip': true, },

                { key: 'isFirstArrival', label: 'label_is_first_arrival', 'width': 100, formatter: (r, c, v) => this.$enumShow(v, "YesOrNoEnum") },

                {
                  key: 'acceptanceQty', label: 'label_acceptance_number', 'width': 110,
                },
                {
                  key: 'skuAcceptanceAttachedList', label: 'label_acceptance_photo', 'min-width': 175, keyShowForce: [true],
                  render: (h, { row }) => {
                    return (<div style="text-align:start">
                      <ex_super_upload value={row['skuAcceptanceAttachedList']} type='image' limit={4}
                        accept='image/png,image/jpeg'
                        imageBoxSize={70} multiple={true}
                        disabled={true}
                        onInput={e => {
                          e.forEach(it => it.fileType = it.fileExt )
                          this.$set(row, 'skuAcceptanceAttachedList', e);
                        }}
                        onIsUploadChange={e => this.$set(row, 'isUpload', e)}
                        headers={{ targetFolder: 'wms/acceptance' }}
                      >
                      </ex_super_upload>
                    </div>)
                  }
                },

                {
                  key: 'check_dimension',
                  label: 'label_check_info', 'width': 220, render: (h, { row }) => {
                    if ([row.checkSkuWeight, row.checkSkuLength, row.checkSkuWidth, row.checkSkuHeight].every(it => !it)) return this.$tt('data_temp_none')
                    return (<div>
                      <div>{this.$tt("label_weight") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.checkSkuWeight, 3), "kg"))}</div>
                      <div>{this.$tt("label_length") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.checkSkuLength, 2), "cm"))}</div>
                      <div>{this.$tt("label_width") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.checkSkuWidth, 2), "cm"))}</div>
                      <div>{this.$tt("label_height") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.checkSkuHeight, 2), "cm"))}</div>
                    </div>)
                  }
                },
                {
                  key: 'abnormalQty', label: 'label_abnormal_count', 'width': 110,
                },
                {
                  key: 'anomalyDescribeName', label: 'label_anomaly_desc', 'width': 150,
                },
                {
                  key: 'anomalyAttachedList', label: 'label_abnormal_attachment', 'width': 170,
                  render: (h, { row, column, index }) => {
                    const value = row[column.property]
                    if (_.isEmpty(value)) return this.$renderText(h,null)
                    return (<ex_super_upload value={value} type="file" disabled />)
                  }
                },
              ]
            }
          ],
        }
      },
      dialogSkuCheckRules: {
        dimension: {
          required: true, trigger: 'blur', validator: (r, v, cb) => {
            let checkValueList = [v.checkSkuWeight, v.checkSkuLength, v.checkSkuWidth, v.checkSkuHeight]
            if (checkValueList.some(item => !_.isEmpty(item))) {
              if (checkValueList.some(item => _.isEmpty(item) || !(Number(item) > 0))) {
                return cb(this.$tt("tip_only_positive_number"))
              } else if ([v.checkSkuWeight].some(item => !this.$reg.DigitNumber(item, 3, 9))) {
                return cb(this.$tt("tip_type_only_digit_int_length", { type: this.$tt('label_check_weight'), digit: 3, int: 9 }))
              } else if ([v.checkSkuLength, v.checkSkuWidth, v.checkSkuHeight].some(item => !this.$reg.DigitNumber(item, 2, 9))) {
                return cb(this.$tt("tip_type_only_digit_int_length", { type: this.$tt('label_check_dimension'), digit: 2, int: 9 }))
              }
            }
            cb()
          }
        },
      },
      dialogSkuCheck: {
        customClass: 'dialog_extra',
        form: {
          model: [
            { key: 'tip', formType: 'text', inputClass: "bold ", },
            {
              key: 'items', label: 'label_check_info',
              formType: 'table', 'height': 400,
              model: [
                { key: 'skuOnlyCode', label: 'label_sku_only_code', 'min-width': 120, 'show-overflow-tooltip': true, },
                { key: 'skuName', label: 'label_sku_name', 'min-width': 120, 'show-overflow-tooltip': true, },
                { key: 'isFirstArrival', label: 'label_is_first_arrival', 'width': 100, formatter: (r, c, v) => this.$enumShow(v, "YesOrNoEnum") },
                {
                  key: 'dimension',
                  label: 'label_filing_dimension', 'width': 220, render: (h, { row }) => {
                    if ([row.skuWeight, row.skuLength, row.skuWidth, row.skuHeight].every(it => !it)) return this.$tt('data_temp_none')
                    return (<div>

                      <div>{this.$tt("label_weight") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.skuWeight, 3), "kg"))}</div>
                      <div>{this.$tt("label_length") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.skuLength, 2), "cm"))}</div>
                      <div>{this.$tt("label_width") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.skuWidth, 2), "cm"))}</div>
                      <div>{this.$tt("label_height") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.skuHeight, 2), "cm"))}</div>
                    </div>)
                  }
                },
                {
                  key: 'check_dimension',
                  label: 'label_check_info', 'min-width': 180, render: (h, { row, index }) => {
                    return (<el-form-item prop={`items.${index}`} rules={this.dialogSkuCheckRules.dimension}>
                      <ex_super_input size="mini" value={row.checkSkuWeight}
                        placeholder="label_check_weight" append="KG" appendClass="input_slot_div_mini"
                        onInput={e => this.$set(row, 'checkSkuWeight', e.trim())} />
                      <ex_super_input size="mini" value={row.checkSkuLength}
                        placeholder="label_check_length" append="CM" appendClass="input_slot_div_mini"
                        onInput={e => this.$set(row, 'checkSkuLength', e.trim())} />
                      <ex_super_input size="mini" value={row.checkSkuWidth}
                        placeholder="label_check_width" append="CM" appendClass="input_slot_div_mini"
                        onInput={e => this.$set(row, 'checkSkuWidth', e.trim())} />
                      <ex_super_input size="mini" value={row.checkSkuHeight}
                        placeholder="label_check_height" append="CM" appendClass="input_slot_div_mini"
                        onInput={e => this.$set(row, 'checkSkuHeight', e.trim())} />
                    </el-form-item>)
                  }
                },

              ]
            }
          ],
          rules: {


          }
        }

      },
      dialogAbnormalCheckRules: {
        abnormalQty: { required: true, type: "number", min: 0, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
        anomalyDescribeCode: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
        isUpload: {
          required: true, trigger: 'blur',
          validator: (r, v, cb) => {
            if (v == true) {
              return cb(this.$tt("label_uploading"))
            }
            cb()
          }
        },
      },
      dialogAbnormalCheck: {
        customClass: 'dialog_extra',
        form: {
          model: [
            { key: 'tip', formType: 'text', inputClass: "bold ", },
            {
              key: 'abnormals', label: 'label_check_info',
              formType: 'table', 'height': 400,
              model: [
                {
                  key: 'boxNo', label: 'label_box_code', 'min-width': 140,
                },
                { key: 'skuOnlyCode', label: 'label_sku_only_code', 'min-width': 140, },
                { key: 'skuName', label: 'label_sku_name', 'min-width': 120, 'show-overflow-tooltip': true, },
                {
                  key: 'acceptanceQty', label: 'label_acceptance_number', 'width': 120,
                },
                {
                  key: 'abnormalQty', label: 'label_abnormal_count', 'min-width': 150, "label-class-name": "label_require_before",
                  render: (h, { row, column, index }) => {
                    const value = row[column.property]

                    return (
                      <el-form-item prop={`items.${index}.${column.property}`} rules={this.dialogAbnormalCheckRules.abnormalQty}>
                        <el-input-number value={value} class="w_fill" min={0} max={row.acceptanceQty}
                          placeholder={this.$t("label_abnormal_count")}
                          onInput={e => {
                            this.$set(row, column.property, e)
                          }} />
                      </el-form-item>)
                  }
                },
                {
                  key: 'anomalyDescribeCode', label: 'label_anomaly_desc', 'min-width': 150, "label-class-name": "label_require_before",
                  render: (h, { row, column, index }) => {
                    const value = row[column.property]
                    return (<el-form-item prop={`items.${index}.${column.property}`} rules={this.dialogAbnormalCheckRules.anomalyDescribeCode}>
                      <ex_select_auto value={value} class="w_fill" url={this.$url['wms/BaseAnomalyDescribeClassifyByNode']}
                        urlParams={{ processNodeList: 'COMMON', anomalyClassifyCode: "AC-202309010001" }}
                        option={it => ({ label: it.name, value: it.code })}
                        onChangeItem={e => {
                          this.$set(row, 'anomalyDescribeName', e.name)
                          this.$set(row, column.property, e.code)
                        }} />
                    </el-form-item>)
                  }
                },
                {
                  key: 'anomalyAttachedList', label: 'label_abnormal_attachment', 'min-width': 170,
                  render: (h, { row, column, index }) => {
                    const value = row[column.property]
                    return (<el-form-item prop={`items.${index}.isUpload`} rules={this.dialogAbnormalCheckRules.isUpload}>
                      <ex_super_upload value={value} limit={3} type="file"
                        onInput={e => {
                          e.forEach(it => {
                            it.type = 'ABNORMAL'
                            it.fileType = it.fileExt
                          })
                          this.$set(row, column.property, e)
                        }}
                        onIsUploadChange={e => {
                          this.$set(row, 'isUpload', e)
                        }} />

                    </el-form-item>)
                  }
                },
              ]
            }
          ],

        }

      },
    };
  },


  computed: {
    boxNoList() {
      return _.uniqBy(this.tableOrgData, 'boxNo').map(it => it.boxNo)
    },
  },

  methods: {
    option_table_model() {
      return [
        {
          type: 'expandDesc', 'width': 100,
          expandDesc: {
            class: "desc_flex_row",
            column: 4, border: true, direction: 'vertical', labelClassName: 'flex_cell', contentClassName: 'flex_cell',
            model: [],
          },
        },
        // { key: 'boxNumber', label: 'label_box_order_number', 'width': 100, 'show-overflow-tooltip': true, },
        {
          key: 'boxNo', label: 'label_box_code', 'min-width': 200, keyShowForce: [true],
          'render-header': (h, { column }) => {
            return (<div class="flex_col">
              <div>{this.$tt(column.label)}</div>
              <ex_super_input value={this.boxFilter} multiple type="select" size="mini" class="mg_h1" items={this.boxNoList}
                filterable collapse-tags placeholder="label_box_code_filter"
                onInput={e => { this.boxFilter = e }} onChange={this.changeBoxFilter}
              />
            </div>)
          }
        },
        { key: 'skuOnlyCode', label: 'label_sku_only_code', 'min-width': 120, 'show-overflow-tooltip': true, },
        { key: 'skuName', label: 'label_sku_name', 'min-width': 120, 'show-overflow-tooltip': true, },
        { key: 'isFirstArrival', label: 'label_is_first_arrival', 'width': 100, formatter: (r, c, v) => this.$enumShow(v, "YesOrNoEnum") },
        {
          key: 'skuUrl', label: 'label_sku_image', 'width': 120,
          render: (h, { row }) => {
            return (
              <ex_image_view class="page_table_image" src={row.skuUrl} lazy fit="fill" preview-src-list={this.skuUrlList} />
            )
          }
        },
        {
          key: 'receivingType', label: 'label_receiving_way', 'width': 120,
          formatter: (r, c, v, i) => this.$enumShow(v, "ReceivingTypeEnum"),
        },
        { key: 'receivingQty', label: 'label_receiving_number', 'width': 100, },
        {
          key: 'acceptanceStatus', label: 'label_acceptance_status', 'show-overflow-tooltip': true, 'width': 110,
          render: (h, { row, column }) => {
            const value = row[column.property]
            if (!this.disabledEdit(row) && row.acceptanceQty) return (<div class="color_warning">{this.$t('label_acceptance_ing')}</div>)
            return (
              <div >
                {this.$enumShow(value, "AcceptanceStatusEnum")}
              </div>
            )
          }
        },
        // {
        //     key: 'isAutomaticWarehouseArea', label: 'label_is_auto_location', 'width': 110, 'show-overflow-tooltip': true,
        //     formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum")
        //   },
        {
          key: "skuQualityCheckMethod", 'min-width': 160,
          'render-header': (h, { column }) => {
            return (
              <div>
                <div>
                  {this.$t('label_quality_inspection_method')}
                </div>
                <div>
                  {this.$t('label_sampling_acceptance_ratio')}
                </div>
                <div>
                  {this.$t('label_acceptance_requirements')}
                </div>
              </div>
            )
          },
          render: (h, { row }) => {

            return (<div>
              <div>{this.$renderText(h, this.$enumShow(row.skuQualityCheckType, "SkuQualityCheckTypeEnum"))}</div>
              <div>{this.$renderText(h,row.samplingRatio ? (`${row.samplingRatio} %`) : null)} </div>
              <div>{this.$renderText(h, this.$enumShow(row.skuQualityCheckMethod, "SkuQualityCheckMethodEnum"))}</div>
              <div>{this.$renderText(h, this.$enumShow(row.skuQualityCheckContent ?row.skuQualityCheckContent.split(','):"", "SkuQulityCheckContentEnum"))}</div>
            </div>)
          }
        },
        {
          key: 'acceptanceQty', label: 'label_acceptance_number', 'min-width': 160, keyShowForce: [true],
          "label-class-name": "label_require_before",
          render: (h, { row }) => {
            if (this.disabledEdit(row)) return (<div>{row.acceptanceQty}</div>)
            return (<div>
              <el-input-number value={row.acceptanceQty} class="w_fill" min={0} max={row.receivingQty}
                placeholder={this.$t("label_acceptance_number")}
                onInput={e => {
                  this.$set(row, 'acceptanceQty', e)
                }} />
            </div>)
          }
        },
        {
          key: 'skuAcceptanceAttachedList', label: 'label_acceptance_photo', 'min-width': 175, keyShowForce: [true],
          "render-header": (h, { column }) => {
            return (<div >
              <span>{this.$tt(column.label)}</span>
              <div class="color_warning">{this.$tt("tip_place_submit_sku_weight_len_width_height_photo")}</div>
            </div>)
          },
          render: (h, { row }) => {
            if (this.disabledEdit(row)) return null
            return (<div style="text-align:start">
              <ex_super_upload value={row['skuAcceptanceAttachedList']} type='image' limit={4}
                accept='image/png,image/jpeg'
                imageBoxSize={70} multiple={true}
                onInput={e => {
                  e.forEach(it => it.fileType = it.fileExt )
                  this.$set(row, 'skuAcceptanceAttachedList', e);
                }}
                onIsUploadChange={e => this.$set(row, 'isUpload', e)}
                headers={{ targetFolder: 'wms/acceptance' }}
              >
              </ex_super_upload>
            </div>)
          }
        },
        {
          key: 'isAbnormal', label: 'label_check_abnormal', 'min-width': 160, keyShowForce: [true],
          'render-header': (h, { column }) => {
            return (
              <div>
                <div>
                  {this.$t('label_check_abnormal')}
                </div>
                <div>
                  {this.$t('label_abnormal_count')}
                </div>
              </div>
            )
          },
          render: (h, { row, column }) => {
            const value = row[column.property]

            if (this.disabledEdit(row)) {
              return (<div>
                <div>
                  {row.isAbnormal == 'Y' ? (<span class="color_danger">{this.$t('label_abnormal')}</span>) : (<span class="color_primary">{this.$t('label_normal')}</span>)}
                </div>
                <div>
                  {(row.isAbnormal == 'Y' && row.abnormalQty) ? this.$tt('label_abnormal_count_pieces', { count: row.abnormalQty }) : null}
                </div>
                <div>
                  {(row.isAbnormal == 'Y' && row.abnormalId) ? (<el-button type="text" onClick={
                    e => this.$router.push({ path: '/page/wms/anomaly/anomaly_detail', query: { id: row.abnormalId, } })
                  }>{this.$t('label_view_detail')}</el-button>) : null}
                </div>

              </div>)
            }
            const checknode = (
              <ex_checkbox_yn value={value} class="w_fill" onInput={e => this.$set(row, column.property, e)} ><span class="color_danger">{this.$t('label_abnormal')}</span></ex_checkbox_yn>
            )
            const numbernode = (<el-input-number value={row.abnormalQty} class="w_fill" min={0} max={row.acceptanceQty}
              placeholder={this.$t("label_abnormal_count")}
              onInput={e => {
                this.$set(row, 'abnormalQty', e)
              }} />)
            return (<div>
              {checknode}
              {value == 'Y' ? numbernode : null}
            </div>)
          }
        },

        {
          key: 'dimension',
          label: 'label_filing_dimension', 'width': 220, render: (h, { row }) => {
            if ([row.skuWeight, row.skuLength, row.skuWidth, row.skuHeight].every(it => !it)) return this.$tt('data_temp_none')
            return (<div>
              <div>{this.$tt("label_weight") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.skuWeight, 3), "kg"))}</div>
              <div>{this.$tt("label_length") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.skuLength, 2), "cm"))}</div>
              <div>{this.$tt("label_width") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.skuWidth, 2), "cm"))}</div>
              <div>{this.$tt("label_height") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.skuHeight, 2), "cm"))}</div>
            </div>)
          }
        },
        {
          key: 'check_dimension',
          label: 'label_check_info', 'width': 220, render: (h, { row }) => {
            if ([row.checkSkuWeight, row.checkSkuLength, row.checkSkuWidth, row.checkSkuHeight].every(it => !it)) return this.$tt('data_temp_none')
            return (<div>
              <div>{this.$tt("label_weight") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.checkSkuWeight, 3), "kg"))}</div>
              <div>{this.$tt("label_length") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.checkSkuLength, 2), "cm"))}</div>
              <div>{this.$tt("label_width") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.checkSkuWidth, 2), "cm"))}</div>
              <div>{this.$tt("label_height") + " : "}{this.$renderText(h, this.$addUnit(this.$formatDigit(row.checkSkuHeight, 2), "cm"))}</div>
            </div>)
          }
        },

      ]
    },
    printSkuTag() {
      const list = this.tableData
      if (!_.isEmpty(list)) {
        this.$confirm(this.$tt('tip_is_confirm_print_inbound_order_sku_count'), this.$tt('label_tip'), {
          type: 'warning'
        }).then(() => {
          const uq = _.uniqBy(list, it => it.skuId).map(it => {
            const outIt = _.cloneDeep(it)
            const num = _.reduce(list.filter(item => item.skuId == outIt.skuId), (r, v) => this.$math_add(r, Number(v.quantity)), 0)
            this.$set(outIt, 'printNum', num)
            return outIt
          })
          this.$refs.print_sku.show(uq)
        }).catch((action) => {
          if (action === 'cancel') {
            const uq = _.uniqBy(list, it => it.skuId)
            this.$refs.print_sku.show(uq)
          }
        });

      }
    },
    changeBoxFilter(e) {
      if (_.isEmpty(e)) {
        this.tableData = this.form.list
      } else {
        this.tableData = _.filter(this.form.list, it => {
          return e.includes(it.boxNo)
        })
      }

    },
    changeCheckCount(row, e) {
      this.$set(row, 'acceptanceQty', e)
    },

    isHasAcceptance(row) {
      return row.acceptanceStatus == 'ACCEPTANCE_COMPLETED'
    },
    disabledEdit(row) {
      return this.isHasAcceptance(row) || row.receivingStatus == 'NOT_RECEIVING'
    },
    disabledAbnormal(row) {
      return row.isAbnormal != 'Y'
    },
    cellClassName({ row, column, rowIndex, columnIndex }) {
      if (this.disabledEdit(row)) {
        return 'tableCell_disabled'
      }
      return 'tableCell_noHoverLight'
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (['boxNumber', 'boxNo',].some(it => it == column.property)) {
        return { rowspan: row.rowspan, colspan: 1 }
      }
    },
    init_data_default(into_params) {
      let params = into_params
      let search = params
      if (!_.isEmpty(search)) {
        this.inboundOrderCode = ""
        this.inboundOrderId = ""
        this.$refs['SuperTablePage'].setSearchData(Object.assign({}, this.$refs['SuperTablePage'].getSearchData(), search))
        let _keys = Object.keys(search)
        this.option.search.model.forEach(it => {
          if (it.keylist) {
            let _new_key = _.head(_.intersection(it.keylist.map(_k => _k.value), _keys))
            if (_new_key) it.key = _new_key
          }
        })
        this.$nextTick(() => {
          this.$refs['SuperTablePage'].loadDataForSearch()
        })
      }
    },
    dataHandle(res) {
      if (!res.data || !res.data.inboundOrderCode) {
        this.$message.warning(this.$tt('tip_search_no_data'))
        return []
      }

      this.inboundOrderId = res.data.inboundOrderId
      this.inboundOrderCode = res.data.inboundOrderCode
      this.isAutomaticWarehouseArea = res.data.isAutomaticWarehouseArea

      const noBoxCode = (res.data.boxIsEmpty == 'Y' && !_.isEmpty(res.data.inboundOrderSkuList))
      let _list = noBoxCode ? res.data.inboundOrderSkuList : res.data.boxDetailList
      if (noBoxCode) {
        _list.forEach(it => it.boxDetailId = it.id)
      }
      this.skuUrlList = _list.map(it => it.skuUrl)


      const wms_standard_acceptance_default_plan_count = this.$default_auth_check("wms_standard_acceptance_default_plan_count")


      let currentUser = this.$loginUser

      _list.forEach((it, i) => {


        it.skuAcceptanceAttachedList = []
        it.acceptanceTime = null

        if (!it.acceptanceQty) it.acceptanceQty = 0
        it.abnormalCause = null

        if (wms_standard_acceptance_default_plan_count) {
          it.acceptanceQty = Number(it.receivingQty)
        }

        it._link = _list.filter(it2 => it2.boxNo == it.boxNo)
        if (it.rowspan == undefined) {
          it._link.forEach(it2 => it2.rowspan = 0)
          it.rowspan = it._link.length
        }
      })

      this.boxFilter = []
      this.form.list = _list.sort((a, b) => a.boxNumber - b.boxNumber)
      this.tableData = this.form.list
      return this.form.list
    },

    checkSkuSize() {
      if (_.isEmpty(this.inboundOrderCode)) {
        return this.$message.error(this.$tt('tip_please_first_search'))
      }
      //清除不能编辑的条目
      let _hasList = this.getData().filter(it => !this.disabledEdit(it))
      if (_.isEmpty(_hasList)) {
        return this.$message.error(this.$tt('tip_check_content_no_empty'))
      }

      this.$refs.dialogSkuCheck.showNew({
        data: {
          items: _.uniqBy(_hasList, it => it.skuId),
        },
        onlySetData: true,
      })
    },
    checkSkuSuccess(data) {
      this.getData().filter(it => !this.disabledEdit(it)).forEach(sku => {
        const checkResult = data.items.find(check => check.skuId == sku.skuId &&
          !_.isEmpty(check.checkSkuWeight) && !_.isEmpty(check.checkSkuLength) &&
          !_.isEmpty(check.checkSkuWidth) && !_.isEmpty(check.checkSkuHeight))
        if (checkResult) {
          this.$set(sku, 'checkSkuWeight', checkResult.checkSkuWeight)
          this.$set(sku, 'checkSkuLength', checkResult.checkSkuLength)
          this.$set(sku, 'checkSkuWidth', checkResult.checkSkuWidth)
          this.$set(sku, 'checkSkuHeight', checkResult.checkSkuHeight)
        }
      })
    },
    checkAbnormalSuccess(data) {
      this.showConfirmDialog(data.items)
    },
    showConfirmDialog(_list) {
      let _acceptanceQty = _.reduce(_list, (sum, it) => sum + it.acceptanceQty, 0)
      const showList = _.cloneDeep(_list)
      showList.filter(it => it.isAbnormal != 'Y').forEach(it => {
        it.anomalyAttachedList = []
        it.abnormalQty = null
        it.anomalyDescribeCode = null
        it.anomalyDescribeName = null
      })
      this.$refs.dialogCheckConfirm.showNew({
        data: {
          inboundOrderId: this.inboundOrderId,
          inboundOrderCode: this.inboundOrderCode,
          actualPieceNumber: _acceptanceQty,
          items: showList,
        },
        onlySetData: true,
      })
    },
    clickCheck() {
      if (_.isEmpty(this.inboundOrderCode)) {
        return this.$message.error(this.$tt('tip_please_first_search'))
      }
      //清除不能编辑的条目
      let _hasList = this.getData().filter(it => !this.disabledEdit(it))
      let _list = _hasList.filter(it => !!it.acceptanceQty)
      if (_.isEmpty(_list)) {
        return this.$message.error(this.$tt('tip_acceptance_content_no_empty'))
      }
      if (_list.some(it => it.isAbnormal == 'Y')) {
        this.$refs.dialogAbnormal.showNew({
          data: {
            items: _list,
            abnormals: _list.filter(it => it.isAbnormal == 'Y'),
          },
          onlySetData: true,
        })
      } else {
        this.showConfirmDialog(_list)
      }



    },

    checkSuccess() {
      this.reload()
      this.$emitPage("overseas=>check_manage", "reload")
      this.$emitPage("standard>inbound_manage", "reload")
    },
    submitAcceptanceDataHandle(data) {
      let urlData = {}
      urlData.inboundOrderId = data.inboundOrderId
      urlData.skuDetailList = data.items.map(it => {
        let obj = {
          boxId: it.boxId,
          boxNo: it.boxNo,
          boxDetailId: it.boxDetailId,
          skuId: it.skuId,
          skuBarcode: it.skuBarcode,
          skuOnlyCode: it.skuOnlyCode,
          skuName: it.skuName,
          skuNameEn: it.skuNameEn,
          quantity: it.quantity,
          receivingQty: it.receivingQty,
          acceptanceQty: it.acceptanceQty,

          skuLength: it.skuLength,//	产品长度
          skuWidth: it.skuWidth,//	产品宽度
          skuHeight: it.skuHeight,//	产品高度
          skuWeight: it.skuWeight,//	产品重量

          checkSkuLength: it.checkSkuLength,//	产品长度
          checkSkuWidth: it.checkSkuWidth,//	产品宽度
          checkSkuHeight: it.checkSkuHeight,//	产品高度
          checkSkuWeight: it.checkSkuWeight,//	产品重量
          skuAcceptanceAttachedList:it.skuAcceptanceAttachedList,
          isAbnormal: it.isAbnormal,
        }

        if (it.isAbnormal == 'Y') {
          obj.abnormalQty = it.abnormalQty
          obj.anomalyDescribeCode = it.anomalyDescribeCode
          obj.anomalyAttachedList = it.anomalyAttachedList
        }
        return obj
      })

      return urlData
    },

  }
};

</script>
<style></style>
